<template>
  <div class="services-panel">
    <h4 class="panel-title">{{ config.title || '我的服务' }}</h4>
    <div :class="['service-list', config.layout === 'horizontal' ? 'layout-horizontal' : 'layout-vertical']">
      <!-- 关键修复：v-for 循环 config.data -->
      <div v-for="(item, index) in config.data" :key="index" class="service-item">
        <div class="icon-wrapper">
          <!-- 关键修复：图标字段是 image -->
          <el-image :src="item.image" fit="contain" class="service-icon">
            <div slot="error" class="image-slot"><i class="el-icon-picture-outline"></i></div>
          </el-image>
        </div>
        <span>{{ item.name }}</span>
        <i class="el-icon-arrow-right" v-if="config.layout !== 'horizontal'"></i>
      </div>
      <template v-if="config.layout === 'horizontal' && config.data">
        <div class="service-item-placeholder" v-for="i in (4 - config.data.length % 4) % 4" :key="'p-' + i"></div>
      </template>
    </div>
  </div>
</template>

<script>
  export default {
    name: "MyServicePreview",
    props: ['config']
  }
</script>


<style scoped>
  .mobile-preview {
    width: 375px;
    min-height: 667px;
    background-color: #f7f8fa;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #ebedf0;
  }

  .status-bar {
    height: 20px;
    background-color: #fff;
  }

  .user-info-panel {
    background: linear-gradient(180deg, #5e8dff, #62a1ff);
    padding: 20px 15px;
    color: white;
  }

  .user-info {
    display: flex;
    align-items: center;
  }

  .avatar-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px;
    margin-right: 15px;
  }

  .nickname {
    font-size: 18px;
    font-weight: bold;
  }

  .services-panel {
    margin: 15px;
    background-color: #fff;
    border-radius: 8px;
    padding: 0 15px;
  }

  .panel-title {
    padding: 15px 0;
    margin: 0;
    font-size: 16px;
    border-bottom: 1px solid #f7f8fa;
  }

  .service-list.layout-vertical .service-item {
    display: flex;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #f7f8fa;
  }

  .service-list.layout-vertical .service-item:last-child {
    border-bottom: none;
  }

  .service-list.layout-vertical .service-item span {
    flex: 1;
  }

  .service-list.layout-horizontal {
    display: flex;
    flex-wrap: wrap;
    padding: 15px 0;
  }

  .service-list.layout-horizontal .service-item,
  .service-list.layout-horizontal .service-item-placeholder {
    width: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    font-size: 12px;
  }

  .service-list.layout-horizontal .service-item span {
    margin-top: 8px;
  }

  .icon-wrapper {
    width: 24px;
    height: 24px;
    margin-right: 10px;
  }

  .service-icon {
    width: 100%;
    height: 100%;
  }

  .service-list.layout-horizontal .icon-wrapper {
    width: 32px;
    height: 32px;
    margin-right: 0;
  }

  .ad-placeholder {
    margin: 15px;
    height: 100px;
    border-radius: 8px;
    background-color: #e9e9e9;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
  }
</style>
